package tc.jv.task5;

import java.util.Iterator;

public class LinkedListVector extends tc.jv.task4.LinkedListVector implements Iterable<Double>
{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 3352148962041850011L;

	// CONSTRUCTORS
	
	public LinkedListVector()
	{
		super();
	}
	
	public LinkedListVector(int size)
	{
		super(size);
	}
	
	public LinkedListVector(double ... values)
	{
		super(values.length);
		for (int i = 0; i < values.length; i++)
			add(values[i]);
	}

	@Override
	public Iterator<Double> iterator()
	{
		Iterator<Double> iterator = new Iterator<Double>()
		{

			private Node cursor = head;
			private int index = 0;
			
			@Override
			public boolean hasNext()
			{
				return index < length;
			}

			@Override
			public Double next()
			{
				cursor = cursor.next;
				index++;
                return cursor.prev.value;
			}

			@Override
			public void remove()
			{
				LinkedListVector.this.remove(index);
			}
			
		};
		
		return iterator;
	}
	
}
